import request from '@/utils/request'

export function getRolePages(params) {
  return request({
    url: '/sys/role/getPage',
    method: 'get',
    params
  })
}
export function getRoleList(params) {
  return request({
    url: '/sys/role/getList',
    method: 'get',
    params
  })
}

export function getRoleMenu(params) {
  return request({
    url: '/sys/role/getRoleMenu',
    method: 'get',
    params
  })
}

export function getRoleById(id) {
  return request({
    url: '/sys/role/getById',
    method: 'get',
    params: { id }
  })
}

export function getRoleDeatilById(id) {
  return request({
    url: '/sys/role/getDetail',
    method: 'get',
    params: { id }
  })
}

export function roleAdd(data) {
  return request({
    url: '/sys/role/saveRole',
    method: 'post',
    data
  })
}

export function roleSaveAndSetFunction(data) {
  return request({
    url: '/sys/role/saveAndSetFunction',
    method: 'post',
    data
  })
}

export function roleUpdate(data) {
  return request({
    url: '/sys/role/editRole',
    method: 'post',
    data
  })
}

export function roleUpdateAndSetFunction(data) {
  return request({
    url: '/sys/role/updateAndSetFunction',
    method: 'post',
    data
  })
}

export function roleUpdateDisabled(ids, enable) {
  let _ids = []
  if (Array.isArray(ids)) _ids = ids
  else _ids = [ids]
  return request({
    method: 'get',
    url: '/sys/role/updateStatus',
    params: {
      ids: _ids.join(','),
      enable
    }
  })
}

export function deleteRole(id) {
  return request({
    url: '/sys/role/delete',
    method: 'get',
    params: {
      id
    }
  })
}

export function roleGrant(data) {
  return request({
    url: '/sys/role/grant',
    method: 'post',
    data
  })
}

export function getAllRole(params) {
  return request({
    url: '/sys/role/getAll',
    method: 'get',
    params: params
  })
}
